// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

// 通过接口登录
Cypress.Commands.add('login', (username, password) => {
    cy.session([username, password],() => {
        cy.request({
          method: 'POST',
          url: 'https://test-auth.cocos.com/jsApi/doSignIn',
          form: true,
          body: {
            'username': username,
            'password': password,
            'autoLogin': true
          },
        })
        cy.request({
            url: 'https://test-auth.cocos.com/sso/signIn', 
            qs:{
                'client_id': 321,
                'url': 'http://ops-dev.cocos.org/cocos-dashboard/dashboard/index'
            }
        })
      })
    })

// 页面右上角搜索
Cypress.Commands.add('search', (placeholder, keyword) => {
  cy.get(`[placeholder="${placeholder}"]`).type(keyword)
  cy.get('.ant-input-search-button').click()
})